home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power Programmierung
/
Power-Programmierung CD 2 (Tewi)(1994).iso
/
doc
/
mir
/
newlines.c
< prev
next >
Wrap
Text File
|
1992-07-02
|
6KB
|
193 lines
/*
* Usage - newlines file_in file_out bytes_per_line
*
* NEWLINES Inserts carriage return and line feed every "file_in"
* bytes. Used to deblock data received in line blocks.
*
* input: A file in which data is broken into units in which every
* unit is precisely the same length, and there are no line
* feeds or carriage returns. In the past this was a common
* way of storing text and fixed length records.
*
* output: The same data, expanded by the addition of carriage returns
* and line feeds. In this form, the data can be further
* analyzed and processed using line-oriented programs.
*
* writeup: MIR TUTORIAL ONE, topic 7
*
* Written: Douglas Lowry Jan 10 92
* Copyright (C) 1992 Marpex Inc.
*
* The MIR (Mass Indexing and Retrieval) Tutorials explain detailed
* usage and co-ordination of the MIR family of programs to analyze,
* prepare and index databases (small through gigabyte size), and
* how to build integrated retrieval software around the MIR search
* engine. The fifth of the five MIR tutorial series explains how
* to extend indexing capability into leading edge search-related
* technologies. For more information, GO IBMPRO on CompuServe;
* MIR files are in the DBMS library. The same files are on the
* Canada Remote Systems BBS. A diskette copy of the Introduction
* is available by mail ($10 US... check, Visa or Mastercard);
* diskettes with Introduction, Tutorial ONE software and the
* shareware Tutorial ONE text cost $29. Shareware registration
* for a tutorial is also $29.
*
* E-mail...
* Compuserve 71431,1337
* Internet doug.lowry%canrem.com
* UUCP canrem!doug.lowry
* Others: doug.lowry@canrem.uucp
*
* FAX... 416 963-5677
*
* "Snail mail"... Douglas Lowry, Ph.D.
* Marpex Inc.
* 5334 Yonge Street, #1102
* North York, Ontario
* Canada M2N 6M2
*
* Related database consultation and preparation services are
* available through:
* Innotech Inc., 2001 Sheppard Avenue E., Suite #118,
* North York, Ontario Canada M2J 4Z7
* Tel. 416 492-3838 FAX 416 492-3843
*
* This program is free software; you may redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* (file 05LICENS) along with this program; if not, write to the
* Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
* USA.
*/
#include <stdio.h>
#include <ctype.h>
#define MAX_BYTES 1024
#define repeat for(;;)
typedef enum _bool
{ FALSE = 0, TRUE = 1 } Bool;
/*
* declarations
*/
void Usage_(), process();
char *Cmdname_() { return( "newlines" ); }
/*
* MAIN
*/
main( argc, argv )
int argc;
char **argv;
{
FILE *fp_in, *fp_out ;
char c10 ;
int bytes_per_ln ;
/* Usage - newlines file_in file_out bytes_per_line */
c10 = argv[1][0] ;
if( argc != 4 || c10 == '-' || c10 == '?' || c10 == '/' )
Usage_();
if(( fp_in = fopen( argv[1], "rb" )) == NULL )
{
fprintf( stderr, "Can't open input file %s\n", argv[1] ) ;
Usage_() ;
}
if(( fp_out = fopen( argv[2], "wb" )) == NULL )
{
fprintf( stderr, "Can't open output file %s\n", argv[2] ) ;
fclose( fp_in ) ;
Usage_() ;
}
bytes_per_ln = atoi( argv[3] );
if( bytes_per_ln < 1 || bytes_per_ln > MAX_BYTES )
{
fprintf( stderr, "\nAllowable bytes per line is 1 to %d.\n",
MAX_BYTES );
Usage_() ;
}
process( fp_in, fp_out, bytes_per_ln ) ;
fclose( fp_in ) ;
fclose( fp_out ) ;
exit( 0 );
}
/*
* Usage
*/
void
Usage_()
{
fprintf( stderr,
"\nusage: %s file_in file_out bytes_per_line\n\n\
Inserts carriage return and line feed every \"file_in\"\n\
bytes. Used to deblock data received in line blocks.\n\n\
input: A file in which data is broken into units in which every\n",
Cmdname_() ) ;
fprintf( stderr,
" unit is precisely the same length, and there are no line\n\
feeds or carriage returns. In the past this was a common\n\
way of storing text and fixed length records.\n\n" ) ;
fprintf( stderr,
"output: The same data, expanded by the addition of carriage returns\n\
and line feeds. In this form, the data can be further\n\
analyzed and processed using line-oriented programs.\n\n\
writeup: MIR TUTORIAL ONE, topic 7\n\n" ) ;
exit( 1 ) ;
}
/*
* PROCESS
*/
void
process( fp_in, fp_out, bytes_per )
FILE *fp_in, *fp_out ;
int bytes_per ;
{
unsigned char buf[ MAX_BYTES ] ;
int line_no,
over_120, /* To warn re line length */
ch, /* one character */
len, i ;
repeat
{
if( !fread( buf, sizeof( char ), bytes_per, fp_in ))
{
if( feof( fp_in ))
break ;
else
{
fprintf( stderr, "Unable to read input file... FATAL.\n" );
exit( 1 ) ;
}
}
if( !fwrite( buf, sizeof( char ), bytes_per, fp_out ))
{
fprintf( stderr, "Unable to write... FATAL.\n" );
exit( 1 ) ;
}
fputc( '\015', fp_out ) ;
fputc( '\n', fp_out ) ;
}
return ;
}